package com.bluedot.bank.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.bluedot.bank.dao.role.Role;
import com.bluedot.bank.dao.role.RoleDao;
import com.bluedot.bank.dao.role.RoleDaoImpl;
import com.bluedot.bank.dao.user.User;
import com.bluedot.bank.dao.user.UserDao;
import com.bluedot.bank.dao.user.UserDaoImpl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ModifyUserAction extends ActionSupport {
	private User user;;
	private long id;
	private UserDao userDao=new UserDaoImpl();
	private Role role =new Role();
	private List<Role> roles=new ArrayList<Role>();
	private long roleId;
	/**
	 * @return the roleId
	 */
	public long getRoleId() {
		return roleId;
	}
	/**
	 * @param roleId the roleId to set
	 */
	public void setRoleId(long roleId) {
		this.roleId = roleId;
	}
	/**
	 * @param roles the roles to set
	 */
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	/**
	 * @return the role
	 */
	public Role getRole() {
		return role;
	}
	/**
	 * @param role the role to set
	 */
	public void setRole(Role role) {
		this.role = role;
	}
	/**
	 * @return the roles
	 */
	public List<Role> getRoles() {
		return roles;
	}
	/**
	 * @return the user
	 */
	public User getUser() {
		return user;
	}
	/**
	 * @param user the user to set
	 */
	public void setUser(User user) {
		this.user = user;
	}
	/**
	 * @return the id
	 */
	public long getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(long id) {
		this.id = id;
	}

	public String findUser() throws Exception {
		user=userDao.findById(id);
		role=user.getRole();
		if(role!=null)
		roleId=role.getId();
		RoleDao roleDao=new RoleDaoImpl();
		roles=roleDao.getAll();
		return SUCCESS;
	}

	public String modify() throws Exception {
		RoleDao roleDao=new RoleDaoImpl();
		role=roleDao.findById(roleId);
		user.setRole(role);
		user.setCheck_time(new Date());
		user.setCheck_user((User)ActionContext.getContext().getSession().get("user"));
		userDao.update(user);
		return SUCCESS;
	}

}
